<template>
    <div style="height: 100%" class="warp-2 body-content">
        <navbar :title="$t('mall_29')"></navbar>
        <div class="content-noBottom">
            <van-address-edit
                :save-button-text="$t('mall_30')"
                :show-area="false"
                tel-maxlength="11"
                detail-maxlength="200"
                detail-rows="4"
                @save="onSave"
            />
        </div>
        <common-loading :isLoading="isLoading"></common-loading>
    </div>
</template>

<script>
import { AddressEdit, Dialog } from 'vant';
export default {
    name: 'EditAddress',
    components: {
        vanAddressEdit: AddressEdit,
        vanDialog: Dialog
    },
    data() {
        return {
            isLoading: false
        };
    },
    methods: {
        onSave(data) {
            Dialog.confirm({
                title: this.$t('mall_38'),
                confirmButtonText: this.$t('mall_10'),
                cancelButtonText: this.$t('circle_kg_13')
            }).then(res => {
                this.isLoading = true;
                let requestData = {
                    ielAddress: data.addressDetail,
                    ielConsignee: data.name,
                    ielLinktel: data.tel,
                    ielImpId: this.$route.params.impId
                };
                this.$axios.post('/app/api/trainee/im/exchange', requestData).then(res => {
                    this.isLoading = false;
                    Dialog.alert({
                        title: this.$t('mall_39'),
                        confirmButtonText: this.$t('mall_10'),
                        cancelButtonText: this.$t('circle_kg_13')
                    }).then(res => {
                        this.$router.go(-1);
                    });
                }).catch(res => {
                    this.isLoading = false;
                    Dialog({ message: res.response.data.errMsg });
                });
            });
        }
    }
};
</script>

<style scoped lang="less">
/deep/.van-address-edit{
    padding: 16px;
}
/deep/.van-address-edit__buttons{
    padding: 32px 0;
}
/deep/.van-button--danger{
    // width: 180px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    background: #075ebb;
    color: #ffffff;
    border-radius: 4px;
    border: none;
}
</style>
